home *** CD-ROM | disk | FTP | other *** search
- unit Tabtest;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Controls,
- Forms, Dialogs, TabUtils, StdCtrls, DB, DBTables, Grids, DBGrids, Spin,
- DBCtrls, TabNotBk, ShellAPI ;
-
- type
- TForm1 = class(TForm)
- DataSource1: TDataSource;
- Tabley: TTable;
- Queryy: TQuery;
- Notebook: TTabbedNotebook;
- FieldNameNum: TSpinEdit;
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- Label1: TLabel;
- Label3: TLabel;
- Button10: TButton;
- Button11: TButton;
- Button12: TButton;
- Button6: TButton;
- Button7: TButton;
- Button9: TButton;
- ExportTypeDD: TComboBox;
- ExportPath: TEdit;
- Button4: TButton;
- Button5: TButton;
- FieldsDD: TComboBox;
- GroupSumLB: TListBox;
- Label2: TLabel;
- DBGrid1: TDBGrid;
- Label4: TLabel;
- Label6: TLabel;
- Label7: TLabel;
- Label5: TLabel;
- Button13: TButton;
- QueryySYMBOL: TStringField;
- QueryyCO_NAME: TStringField;
- QueryyEXCHANGE: TStringField;
- QueryyCUR_PRICE: TFloatField;
- QueryyYRL_HIGH: TFloatField;
- QueryyYRL_LOW: TFloatField;
- QueryyP_E_RATIO: TFloatField;
- QueryyBETA: TFloatField;
- QueryyPROJ_GRTH: TFloatField;
- QueryyINDUSTRY: TSmallintField;
- QueryyPRICE_CHG: TSmallintField;
- QueryySAFETY: TSmallintField;
- QueryyRATING: TStringField;
- QueryyRANK: TFloatField;
- QueryyOUTLOOK: TSmallintField;
- QueryyRCMNDATION: TStringField;
- QueryyRISK: TStringField;
- Button8: TButton;
- Button14: TButton;
- procedure FormActivate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure Button4Click(Sender: TObject);
- procedure Button5Click(Sender: TObject);
- procedure Button6Click(Sender: TObject);
- procedure Button7Click(Sender: TObject);
- procedure Button9Click(Sender: TObject);
- procedure Button10Click(Sender: TObject);
- procedure Button11Click(Sender: TObject);
- procedure Button12Click(Sender: TObject);
- procedure Button13Click(Sender: TObject);
- procedure Button8Click(Sender: TObject);
- procedure Button14Click(Sender: TObject);
-
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- label1.Caption := 'The selected field is called ' + GetFieldName('DBDEMOS', 'MASTER.DBF', FieldNameNum.Value) ;
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- If (FieldsDD.ItemIndex = 7) or (FieldsDD.ItemIndex = 8) then
- MessageDlg('Cannot Perform Calculations on Text Fields', mtInformation, [mbOK], 0)
- else begin
- label2.Caption := 'Column Total for ' + FieldsDD.Text + ' = ' +
- FloattoStr(ColumnTotal('DBDEMOS', 'MASTER.DBF', FieldsDD.Text)) ;
- end ;
- end;
-
- procedure TForm1.Button3Click(Sender: TObject);
- var
- fldlist : TStringList ;
- xx : Integer ;
- begin
- xx := 0 ;
- Tabley.Active := False ;
- Tabley.TableName := 'OUTPUT.DB' ;
- DataSource1.DataSet := Tabley ;
- fldlist := TStringList.Create ;
- fldlist.Clear ;
- While xx <> 10 do begin
- If GroupSumLB.Selected[xx] = True then
- fldlist.Add(GroupSumLB.Items.Strings[xx]) ;
- Inc(xx) ;
- end ;
-
- If GroupSummary('DBDEMOS', 'MASTER.DBF', 'OUTPUT.DB', FieldsDD.Text, fldlist) = 0 then
- MessageDlg('Table created OK', mtInformation, [mbOK], 0)
- else
- MessageDlg('Table not created', mtWarning, [mbOK], 0) ;
-
- fldlist.Free ;
- Tabley.Active := True ;
- end;
-
- procedure TForm1.Button4Click(Sender: TObject);
- begin
- Queryy.Active := False ;
- DataSource1.DataSet := Queryy ;
- Queryy.Active := True ;
-
- If (FieldsDD.ItemIndex = 7) or (FieldsDD.ItemIndex = 8) then
- MessageDlg('Cannot Perform Calculations on Text Fields', mtInformation, [mbOK], 0)
- else begin
- label2.Caption := 'Column Total for ' + FieldsDD.Text + ' = ' +
- FloattoStr(DS_ColumnTotal(Queryy, FieldsDD.Text)) ;
- end ;
- end;
-
- procedure TForm1.Button5Click(Sender: TObject);
- begin
- Tabley.Active := False ;
- Tabley.TableName := 'MASTER.DBF' ;
- DataSource1.DataSet := Tabley ;
- Tabley.Active := True ;
-
- If (FieldsDD.ItemIndex = 7) or (FieldsDD.ItemIndex = 8) then
- MessageDlg('Cannot Perform Calculations on Text Fields', mtInformation, [mbOK], 0)
- else begin
- label2.Caption := 'Column Total for ' + FieldsDD.Text + ' = ' +
- FloattoStr(DS_ColumnTotal(Tabley, FieldsDD.Text)) ;
- end ;
- end;
-
- procedure TForm1.Button6Click(Sender: TObject);
- var
- fldlist : TStringList ;
- xx : Integer ;
- exptype : TFFormat ;
- begin
- xx := 0 ;
- fldlist := TStringList.Create ;
- fldlist.Clear ;
- While xx <> 10 do begin
- If GroupSumLB.Selected[xx] = True then
- fldlist.Add(GroupSumLB.Items.Strings[xx]) ;
- Inc(xx) ;
- end ;
- Tabley.Active := False ;
- Tabley.TableName := 'OUTPUT.DB' ;
- Tabley.Active := True ;
- DataSource1.DataSet := Tabley ;
- Tabley.Edit ;
- Tabley.Delete ;
-
- case ExportTypeDD.ItemIndex of
- 0 : exptype := fftCSV ;
- 1 : exptype := fftFixed ;
- 2 : exptype := fftQuoted ;
- end ;
-
- If DS_ExportToTxt(Tabley, ExportPath.Text, fftCSV, True) then begin
- MessageDlg('File Created OK', mtInformation, [mbOK], 0) ;
- DataSource1.DataSet.Active := True ;
- end
- else
- MessageDlg('File Not Created ', mtWarning, [mbOK], 0) ;
-
- fldlist.Free ;
- end;
-
- procedure TForm1.Button7Click(Sender: TObject);
- var
- exptype : TFFormat ;
- begin
- case ExportTypeDD.ItemIndex of
- 0 : exptype := fftCSV ;
- 1 : exptype := fftFixed ;
- 2 : exptype := fftQuoted ;
- end ;
-
- If ExportToTxt('DBDEMOS', 'MASTER.DBF', Exportpath.Text, exptype, True) then
- MessageDlg('File created OK', mtInformation, [mbOK], 0)
- else
- MessageDlg('File not created ', mtWarning, [mbOK], 0) ;
- end;
-
- procedure TForm1.Button9Click(Sender: TObject);
- begin
- If AppendFromCSV('DBDEMOS', 'FROMCSV.DB', 'FROMCSV.TXT') then
- MessageDlg('Table updated OK', mtInformation, [mbOK], 0)
- else
- MessageDlg('Table not updated ', mtWarning, [mbOK], 0) ;
- end;
-
- procedure TForm1.Button10Click(Sender: TObject);
- begin
- If (FieldsDD.ItemIndex = 7) or (FieldsDD.ItemIndex = 8) then
- MessageDlg('Cannot Perform Statistical Functions on Text Fields', mtInformation, [mbOK], 0)
- else
- label3.Caption := 'Minimum Value in ' + FieldsDD.Text + ' field is ' +
- FloattoStr(ColumnStatVal(sfMIN, 'DBDEMOS', 'MASTER.DBF', FieldsDD.Text)) ;
- end;
-
- procedure TForm1.Button11Click(Sender: TObject);
- begin
- If (FieldsDD.ItemIndex = 7) or (FieldsDD.ItemIndex = 8) then
- MessageDlg('Cannot Perform Statistical Functions on Text Fields', mtInformation, [mbOK], 0)
- else
- label3.Caption := 'Maximum Value in ' + FieldsDD.Text + ' field is ' +
- FloattoStr(ColumnStatVal(sfMAX, 'DBDEMOS', 'MASTER.DBF', FieldsDD.Text)) ;
- end;
-
- procedure TForm1.Button12Click(Sender: TObject);
- begin
- If (FieldsDD.ItemIndex = 7) or (FieldsDD.ItemIndex = 8) then
- MessageDlg('Cannot Perform Statistical Functions on Text Fields', mtInformation, [mbOK], 0)
- else
- label3.Caption := 'Average Value in ' + FieldsDD.Text + ' field is ' +
- FloattoStr(ColumnStatVal(sfAVG, 'DBDEMOS', 'MASTER.DBF', FieldsDD.Text)) ;
- end;
-
- procedure TForm1.FormActivate(Sender: TObject);
- begin
- Tabley.TableName := 'MASTER.DBF' ;
- Tabley.Open ;
- Tabley.Close ;
- FieldsDD.ItemIndex := 8 ; { Select Risk as default field }
- GroupSumLB.Selected[0] := True ; { Select a field in list }
- ExportTypeDD.ItemIndex := 0 ; { Comma Separated }
- end;
-
- procedure TForm1.Button13Click(Sender: TObject);
- begin
- { View output file }
- ShellExecute(0, NIL, 'C:\EXP2TXT.TXT' + #0, NIL, NIL, 1) ;
- end;
-
- procedure TForm1.Button8Click(Sender: TObject);
- begin
- If CreateFromCSV('DBDEMOS', 'FROMCSV.DB', 'FROMCSV.TXT', False) then
- MessageDlg('Table created OK', mtInformation, [mbOK], 0)
- else
- MessageDlg('Table not created ', mtWarning, [mbOK], 0) ;
- end;
-
- procedure TForm1.Button14Click(Sender: TObject);
- begin
- Close ;
- end;
-
- end.
-